package game.model
{
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	import game.common.Reflection;
	import game.managers.ConfigManager;
	
	public class MenuModel extends EventDispatcher
	{
		private static var instance:MenuModel;	
		
		/**dataxml数据*/
		public var xml:XML;
		/**存放菜式数据*/
		private var _dataArr:Array=[];
		
		public function MenuModel()
		{
			if (!instance) {
				instance = this;
				init();
			}else
				throw new Error("MenuModel is a single class");
		}
		
		public static function getInstance():MenuModel
		{
			if (!instance)
				instance = new MenuModel();
			return  instance;
		}
		
		private function init():void
		{
			if (ConfigManager.CONNECT_SERVER) 
			{
				loadServerData();	
			}
		}
		
		/**
		 * 读取上次数据,dataxml
		 * */
		private function loadServerData():void
		{
			xml = Reflection.dataLoader.content as XML;
			
			Global.nowEx = int(xml.global.nowEx);
			Global.totalEx = int(xml.global.totalEx);
			Global.level = int(xml.global.level);
			Global.money = int(xml.global.money);
			
			/**第一道菜式的数据*/
			var obj:Object = new Object();
			if (xml.menu.first == null) 
			{
				obj = null;
				//Global.foodArr[0] = null;
			}else{
				obj.source = String(xml.menu.first);
				obj.num = int(xml.menu.firstNum);
				obj.ex =int(xml.menu.firstEx);
				obj.price = int(xml.menu.firstPrice);
				Global.foodArr[0] = obj.source;
			}			
			_dataArr.push(obj);
			Global.foodDataArr[0] = obj;
			
			
			/**第2道菜式的数据*/
			obj = new Object();
			if (xml.menu.second == null) 
			{
				obj = null;
				//Global.foodArr[1] = null;
			}else{
				obj.source = String(xml.menu.second);
				obj.num = int(xml.menu.secondNum);
				obj.ex = int(xml.menu.secondEx);
				obj.price = int(xml.menu.secondPrice);
				Global.foodArr[1] = obj.source;
			}			
			_dataArr.push(obj);
			Global.foodDataArr[1] = obj;
			
			
			/**第3道菜式的数据*/
			obj = new Object();
			if (xml.menu.third == null) 
			{
				obj = null;
				//Global.foodArr[2] = null;
			}else{
				obj.source = String(xml.menu.third);
				obj.num = int(xml.menu.thirdNum);
				obj.ex = int(xml.menu.thirdNumEx);
				obj.price = int(xml.menu.thirdNumPrice);
				Global.foodArr[2] = obj.source;
			}
			
			_dataArr.push(obj);
			Global.foodDataArr[2] = obj;
			
		}
	}
}